# 这是一个python3脚本

import flask
import copy
import os.path
import Service as Service

LOG_FILE_NAME = 'bdc.log'

app = flask.Flask(__name__)
app.debug = True
services = None

@app.route('/')
def default_index():
    return flask.redirect('/index')

@app.route('/<page_name>')
def get_page(page_name):
    file_name = 'web/' + page_name + '.html'
    if os.path.exists(file_name) == False:
        flask.abort(404)
    return flask.send_file(file_name)

@app.route('/res/<file_name>')
def get_resource(file_name):
    return flask.send_file('web/' + file_name)

@app.route('/service/<service_name>')
def handle_service(service_name):
    args = copy.deepcopy(flask.request.args.to_dict())
    if service_name == 'get_books_short_info':
        return services.get_books_short_info(args)
    elif service_name == 'get_lesson_content':
        return services.get_lesson_content(args)
    return 'asdfasdfas'

if __name__ == '__main__':
    app.logger.info('bdc load data')
    services = Service.Service()
    app.logger.info('bdc start.')
    print('!!! 000')
    app.run(host='0.0.0.0')
    #app.run()
    print('!!! 111')
    app.logger.info('bdc exit.')
    print('!!! 222')

